<?php
/**
 * 借款申请单
 * Created by PhpStorm.
 * User: 23783
 * Date: 2018/3/13
 * Time: 13:55
 */
namespace Controllers\Pdf;

class ApplicationLoanPdf{
    protected $pdf;

    public function __construct()
    {
        global $tcPdf;
        $this->pdf  = $tcPdf;
    }
    /**
     * 生成差旅费报销单
     * @param $result
     */
    function CreatePdfDocument($result){
//        var_dump($result);
        $this->pdf->AddPage();
        // 设置文档信息
        $this->pdf->SetCreator('Lane');
        $this->pdf->SetAuthor('Lane');
        $this->pdf->SetTitle('借款申请单');
        //删除预定义的打印 页眉/页尾
        $this->pdf->setPrintHeader(false);
        $this->pdf->setPrintFooter(false);
        //设置字体 - 正文标题的哦。B是加粗，15是大小
        $this->pdf->SetFont('stsongstdlight', 'B', 15);
        $this->pdf->Write(20, '借款申请单', '', 0, 'C', true, 0, false, false, 0);
        //设置字体 - 正文内容的哦。B是加粗，15是大小
        $this->pdf->SetFont('stsongstdlight', '', 10);
        //设置页面边幅：
        $this->pdf->Cell(190, 24, '借款申请单', 1, 1, 'C');

        $this->pdf->Cell(27, 6, '所属部门:', 1, 0, 'R');
        $this->pdf->Cell(27, 6, '', 1, 0, 'C');
        $this->pdf->Cell(27, 6, '申请人姓名:', 1, 0, 'R');
        $this->pdf->Cell(55, 6, '', 1, 0, 'C');
        $this->pdf->Cell(27, 6, '联系电话:', 1, 0, 'R');
        $this->pdf->Cell(27, 6, '', 1, 1, 'C');


        $this->pdf->Cell(27, 6, '接受方式:', 1, 0, 'R');
        $this->pdf->Cell(27, 6, '', 1, 0, 'C');
        $this->pdf->Cell(27, 6, '转账账号:', 1, 0, 'R');
        $this->pdf->Cell(55, 6, '', 1, 0, 'C');
        $this->pdf->Cell(27, 6, '账号抬头:', 1, 0, 'R');
        $this->pdf->Cell(27, 6, '', 1, 1, 'C');


        $this->pdf->Cell(136, 6, '借款说明', 1, 0, 'C');
        $this->pdf->Cell(54, 6, '借款金额', 1, 1, 'C');
        $this->pdf->Cell(136, 6, '', 1, 0, 'C');
        $this->pdf->Cell(54, 6, '', 1, 1, 'C');


        $this->pdf->Cell(27, 6, '合计费用(大写)：', 1, 0, 'C');
        $this->pdf->Cell(109, 6, '', 1, 0, 'L');
        $this->pdf->Cell(27, 6, '合计费用(小写):', 1, 0, 'R');
        $this->pdf->Cell(27, 6, '', 1, 1, 'L');

        //审批记录
//        $stks_count = count($result['task']);
        $stks_count = 10;
        $this->pdf->Cell(27, 6*$stks_count, '审批记录：', 1, 0, 'C');
        for ($tasks=0;$tasks<$stks_count;$tasks++){
            if($tasks>0){
                $this->pdf->Cell(27, 6,'' , 0, 0, 'L');
            }
            $this->pdf->Cell(163, 6, '', 0, 1, 'L');
        }

        $this->pdf->Line($this->pdf->GetX()+190, $this->pdf->GetY()-6*$stks_count, $this->pdf->GetX()+190, $this->pdf->GetY(), $style=array('width'=>0.2));
        $this->pdf->Line(27, $y = $this->pdf->GetY(), 200, $y = $this->pdf->GetY(), $style=array('width'=>0.2));

        //输出PDF。第二个参数默认是I，是浏览器预览。D是下载
        $this->pdf->Output('PHP_TO_PDF.pdf', 'I');
    }
}